# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=faad2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.10.1
pkgrel=1
pkgdesc="ISO AAC audio decoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/knik0/faad2"
license=('GPL')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=($( [[ "${CARCH}" == "aarch64"  ]] || echo "${MINGW_PACKAGE_PREFIX}-yasm" )
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/knik0/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('4c16c71295ca0cbf7c3dfe98eb11d8fa8d0ac3042e41604cfd6cc11a408cf264')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
